#!/usr/bin/perl
# 2012/11/06 Random sampling of lines

use strict;
use warnings;
use IO::File;
use Getopt::Std;
use Carp qw(croak);
$| = 0;

if(@ARGV != 4 or $ARGV[0] eq '--help'){
	die "Usage : $0 -n [% of sampling lines] -i [input file]\n";
}

my %opt;
getopts("i:n:", \%opt);
my $percent = $opt{n};
my $FILE_in = $opt{i};

#my $TOTAL_line = `wc -l < $FILE_in`;
#$TOTAL_line =~ s/\r?\n//;

if($percent >= 1){
	$percent = $percent / 100;
}

my $fh_in = IO::File->new($FILE_in) or die "cannot open $FILE_in: $!";
while($_ = $fh_in->getline()){
	if(rand() < $percent){
		print;
	}
}
$fh_in->close();




